import { AccManageConst } from "src/consts/acc_manage_const";
import * as Api from 'src/api/net';
import { PopupName } from "src/consts/popup_const";

const state: any = {} as any;

state.contact_way = "";
state.dept_list = [];
state.name = "";
state.password = "";
state.remark = "";
state.role_list = [];
state.sex = "";
state.status = "";
// vuex

/** 更新数据的 */
const mutations = {
    [AccManageConst.CommitAdd](state: any, data: any): void {
        state.dept_list = [];
        state.contact_way = data.contact_way;
        state.name = data.name;
        state.password = data.password;
        state.remark = data.remark;
        state.role_list = [];
        state.sex = data.sex;
        state.status = data.status;
    },
    [AccManageConst.CommitAddDept](state: any, data: any): void {
        state.dept_list = data;
        WLLib.panel(PopupName.Acc_Org_Panel).close();
    },
}

//异步处理
const actions = {
    [AccManageConst.DispatchAdd](context: VuexData, data?: any): void {
        Api.AjaxPost(Config.ajaxUrl + "/account/add.do", data, (res: any) => {
            WLMessage("新增账号成功", "success")
            let senData: any = {}
            senData["curr_page"] = WLStore().state.accManage.curr_page
            senData["page_size"] = WLStore().state.accManage.page_size
            WLDispatch(AccManageConst.DispatchList, senData);
            if (!data.isContinue) {
                WLLib.panel(PopupName.Acc_Add_Panel).close();
            }
        })
    }
}

export default {
    state,
    mutations,
    actions
}